<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@page import="edu.ccut.saturn.component.SaturnData"%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
<link href="${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/userModule/page/css/authority.css" rel="stylesheet" type="text/css">
<title>编辑角色信息</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/extjs/js/validate.js">
</script>
</head>
<body>
</body>
</html>
<script>

Ext.onReady(function(){
	Ext.QuickTips.init(); 
	<%@ include file="jsp/general.jsp"%> 
	function getRoleResult(){
		Ext.Ajax.request({
		     method : 'POST',                             //发送方式.'POST'或'GET',一般是'POST'
		     url: '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/roleModule/roleAction/QueryRoleByPK.action',                  //发送到页面
		     success:function(request){                   //发送成功的回调函数
		       	var myResult = Ext.util.JSON.decode(request.responseText);
		       	Ext.get("id").dom.value = myResult.roleResult.id;
		       	Ext.get("name").dom.value = myResult.roleResult.name;		     
		       	Ext.get("descn").dom.value = myResult.roleResult.descn;		  
		     },
		     failure:function(){                          //发送失败的回调函数
		       Ext.Msg.alert("错误", "连接失败，请重试！");
		     },
		     params:{
		     		id:'<%=request.getParameter("id")%>'
		     } 
     	});
    }
	getRoleResult();
	//--------------------------------------------------------------------------------------------
	//						修改角色信息表单
	//
	//--------------------------------------------------------------------------------------------

	var editRole = new Ext.FormPanel({
	    labelWidth: 75,
	    id:'editRole',
	    frame:true,
	    title: '编辑角色信息',
	    bodyStyle:'padding:5px 5px 0',
	    width: 350,
	    defaults: {width: 230},
	    defaultType: 'textfield',
	    items: [ {
	            name: 'id',
	            id: 'id',
	            inputType:'hidden',
	            hidden:true
	        },{
	            fieldLabel: '角色名称',
	            name: 'name',
	            id: 'name',
	            maxLength:10,
	            allowBlank:false,
	            blankText:'角色名称不可为空',
	            vtype: 'isNumberAlphaUnderlineChinese'
	        },{
	        	xtype:'textarea',
	            fieldLabel: '描述',
	            name: 'descn',
	            id: 'descn',
	            //maxLength:50,
	            vtype: 'isNumberAlphaUnderlineChineseSpaceMaxLength200'
	        }
	    ]
	});
	//--------------------------------------------------------------------------------------------
	//						修改角色
	//
	//--------------------------------------------------------------------------------------------
					
     var win = new Ext.Window({
         layout      : 'fit',
         width       : 450,
         height      : 200,
         plain       : true,
         animEl: 'result',
         closable: false,
         items: [editRole],
         buttons: [{
             text     : '修改',
             handler  : function(){
                if(editRole.form.isValid()){
                		editRole.form.submit({					                		
                			url: '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/roleModule/roleAction/UpdateRole.action', 
		               		success : function(form, action) {
		               			var myResult = Ext.util.JSON.decode(action.response.responseText);
		               			
		               				if(myResult.result > 0){
		               					Ext.MessageBox.show({
		               				 		title: '修改成功',
		                                    msg: '恭喜您，修改信息成功！',
		                                    width:200,
		                                    buttons: Ext.MessageBox.OK,
		                                    fn: function(btn) {
										         window.location = '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/roleModule/rolePage/roleList.jsp';
										    }		
		                                 });
		                                
									  } else {
										  	Ext.MessageBox.show({
			                                    title: '修改失败',
			                                    msg: '对不起，修改信息失败！',
			                                    buttons: Ext.MessageBox.OK,
			                                    icon: Ext.MessageBox.ERROR
		                                	});
									  }		                                 
		                        },
                       		   failure: function(form, action) {
                       	
			                       	Ext.MessageBox.show({
			                                   title: '修改失败',
			                                   msg: '对不起，连接失败，请重试！',
			                                   buttons: Ext.MessageBox.OK,
			                                   icon: Ext.MessageBox.ERROR
				                   });
		                       },
               				   waitMsg:'正在修改角色信息，请稍后...'
               			});
                	}else{
                		Ext.MessageBox.alert('警告','对不起，您的信息有误！')
                	}
                }
            },{
                text     : '返回',
                handler  : function(){
                   // window.history.back();
                    window.location = 'roleList.jsp';
                    }
           },{
                text     : '重置',
                handler  : function(){
                    getRoleResult();
                }
            }]
       });
       win.show();
});

</script>